# Definition: at3_xrootdint
#
#  Xrootd is a high performance network storage system widely used in high energy 
#  physics experiments such as ATLAS and ALICE. The underlying Xroot data transfer 
#  protocol provides highly efficient access to ROOT based data files. This class provides 
#  the basis for creating a simple Xrootd storage system consisting of one 
#  redirector node and one or more data server nodes.
#  
#  This installs and configures a read-only xrootdfs fuse mount for an existing xrootd cluster
#
# Parameters:
#   - $fqdnRedirector : fully qualified domain name for the redirector
#   - $mountPoint - the mount point
#   - $storagePath: a directory containing internal Xrootd references to files in the system.
#      Default is '/atlas'
#   
# Actions:
#   - installs xrootd-fuse
#   - sets up the mount point
#   - mounts xrootd
#
# Requires:
#   - This has been tested on SL and SLC 5.5
#   
define at3_xrootdint ($fqdnRedirector,$mountPoint='/xrootdfs/atlas',$ossLocalRoot='/local/xrootd/a',$storagePath='/atlas') 
{
 
  $version='5'
  $basearch='x86_64'
  yumrepo { 'xrootd-stable':
    descr    => 'XRootD Stable repository',
    baseurl  => "http://xrootd.org/binaries/stable/slc/${version}/${basearch} http://xrootd.cern.ch/sw/repos/stable/slc/${version}/${basearch}",
    gpgcheck => '0',
    enabled  => '1',
    priority => '1',
  }
  group { 'xrootd':
    ensure => present,
  }

  user { 'xrootd':
    ensure => present,
    gid    => 'xrootd',
    require=> Group['xrootd'],
  }

  # recursively make all the directories for the mount point 
  exec { "$mountPoint":
    command => "mkdir -p $mountPoint",
    creates => "$mountPoint",
    path    => ['/bin','/usr/bin'],
    require => [User['xrootd']],
    logoutput => true,
    onlyif => ["test -z `mount | grep xrootdfs`"],
  }

  exec { "chown xrootd:xrootd $mountPoint":
    path    => ['/bin','/usr/bin'],
    require => Exec["$mountPoint"],
    logoutput => true,
    onlyif => ["test -z `mount | grep xrootdfs`"],
  } 

  exec { 'install-xrootd-fuse':
    command => 'yum -y --disablerepo=epel install xrootd-fuse',
    path => ['/bin','/usr/bin'],
    creates => '/usr/bin/xrootdfs', 
    require => Yumrepo['xrootd-stable'],
    logoutput => true,
  }

  
  mount { "$mountPoint":
    atboot	=> true,
    device	=> "xrootdfs",
    dump	=> 0,
    ensure	=> mounted,
    fstype	=> fuse,
    options	=> "ro,nonempty,rdr=xroot://${fqdnRedirector}:1094/${storagePath},uid=xrootd",
    pass	=> 0,
    remounts  => false,
    require	=> [Exec['install-xrootd-fuse'],Exec["$mountPoint"]],
  } 
}
